package com.peanut.baby.mvp.main;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewpager.widget.ViewPager;

import com.peanut.baby.AppConfig;
import com.peanut.baby.InitManager;
import com.peanut.baby.R;
import com.peanut.baby.comm.BaseDialog;
import com.peanut.baby.comm.MyViewPagerAdapter;
import com.peanut.baby.comm.SmallPagerAdapter;
import com.peanut.baby.http.ApiException;
import com.peanut.baby.model.Ad;
import com.peanut.baby.model.Advice;
import com.peanut.baby.model.BBSMoment;
import com.peanut.baby.model.HomeData;
import com.peanut.baby.model.LiveGroup;
import com.peanut.baby.model.LiveRoom;
import com.peanut.baby.model.QA;
import com.peanut.baby.model.TodaySubject;
import com.peanut.baby.mvp.bbs.BBSListAdapter;
import com.peanut.baby.mvp.bbs.detail.BBSMomentDetailActivity;
import com.peanut.baby.mvp.bbs.list.BBSListActivity;
import com.peanut.baby.mvp.bind.BindMobileActivity;
import com.peanut.baby.mvp.calendar.CalendarActivity;
import com.peanut.baby.mvp.livedetail.LiveDetailActivity;
import com.peanut.baby.mvp.livedetail.livegroupdetail.LiveGroupDetailActivity;
import com.peanut.baby.mvp.liveroom.LiveRoomActivity;
import com.peanut.baby.mvp.login.LoginActivity;
import com.peanut.baby.mvp.main.circle.CircleTrendViewPagerAdapter;
import com.peanut.baby.mvp.main.expert.live.LiveListAdapter;
import com.peanut.baby.mvp.main.expert.qa.QAListAdapter;
import com.peanut.baby.mvp.msg.MsgActivity;
import com.peanut.baby.mvp.qadetail.QADetailActivity;
import com.peanut.baby.mvp.record.RecordEditActivity;
import com.peanut.baby.mvp.search.SearchActivity;
import com.peanut.baby.mvp.sign.SignInActivity;
import com.peanut.baby.mvp.task.TaskActivity;
import com.peanut.baby.mvp.trend.detail.TrendDetailActivity;
import com.peanut.baby.mvp.trend.list.TrendListActivity;
import com.peanut.baby.mvp.web.WebViewActivity;
import com.peanut.baby.util.TimeUtil;
import com.peanut.baby.widget.AutoSwitchViewPager;
import com.peanut.baby.widget.TopDrawableTextView;
import com.peanut.devlibrary.imageloader.ImageLoader;
import com.peanut.devlibrary.util.StringUtil;
import com.peanut.devlibrary.widget.FloatMenuMgr;
import com.tencent.mars.xlog.Log;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by anonymouslystudio on 2017/7/5.
 */

public class HomeFragment extends BaseHomeFragment implements ViewPager.OnPageChangeListener,
        View.OnClickListener,
        HomeFragmentContract.View,
        SwipeRefreshLayout.OnRefreshListener,
        LiveListAdapter.OnLiveRoomJoinListener,
        QAListAdapter.OnQAPraiseClickListener {
    private static final String TAG = HomeFragment.class.getSimpleName();

    @BindView(R.id.swipe_refresh)
    SwipeRefreshLayout swipeRefresh;
    Unbinder unbinder;
    @BindView(R.id.home_live_container)
    LinearLayout liveContainer;
    @BindView(R.id.home_qa_container)
    LinearLayout qaContainer;
    @BindView(R.id.home_circle_container)
    LinearLayout circleContainer;
    @BindView(R.id.home_banner_viewpager)
    ViewPager homeBannerViewpager;
    @BindView(R.id.small_pager)
    AutoSwitchViewPager smallPager;
    @BindView(R.id.home_banner_radiogroup)
    RadioGroup homeBannerRadiogroup;
    @BindView(R.id.home_banner_frame)
    FrameLayout homeBannerFrame;


    @BindView(R.id.home_record)
    TopDrawableTextView homeRecord;
    @BindView(R.id.home_zhenliao)
    TopDrawableTextView homeZhenliao;
    @BindView(R.id.home_suggest)
    TopDrawableTextView homeSuggest;
    @BindView(R.id.home_tiaoli)
    TopDrawableTextView homeTiaoli;
    @BindView(R.id.home_task)
    TextView homeTask;
    @BindView(R.id.home_sign)
    LinearLayout homeSign;
    @BindView(R.id.home_msg)
    FrameLayout homeMsg;
    @BindView(R.id.home_live_bar)
    LinearLayout homeLiveBar;
    @BindView(R.id.home_bbs_bar)
    LinearLayout homeBbsBar;
    @BindView(R.id.bbs_more)
    TextView bbsMore;
    @BindView(R.id.live_more)
    TextView liveMore;
    @BindView(R.id.search_edit)
    TextView SearchEdit;
    @BindView(R.id.qa_more)
    TextView qaMore;
    @BindView(R.id.home_qa_bar)
    LinearLayout homeQaBar;
    protected MyViewPagerAdapter mAdAdapter;                      //banner适配器
    protected List<View> mAdViews;
    protected SmallPagerAdapter smallPagerAdapter;                      //banner适配器
    @BindView(R.id.home_msg_unread)
    ImageView homeMsgUnread;
    @BindView(R.id.home_msg_unread2)
    TextView homeMsgUnread2;
    @BindView(R.id.menu_frame)
    FrameLayout menuFrame;

    @BindView(R.id.group_detail_image)
    ImageView image;
    @BindView(R.id.group_name)
    TextView group_name;
    @BindView(R.id.group_point)
    TextView group_point;
    @BindView(R.id.group_enrole_count)
    TextView group_enrole_count;
    @BindView(R.id.group_room_num)
    TextView group_room_num;
    @BindView(R.id.home_group_bar2)
    View home_group_bar2;
    @BindView(R.id.home_group_bar)
    View home_group_bar;
    @BindView(R.id.group_more)
    View group_more;
    @BindView(R.id.circie_auto_viewpager)
    AutoSwitchViewPager todaySubjectViewPager;
    @BindView(R.id.home_subject_bar)
    View home_subject_bar;
    @BindView(R.id.subject_name)
    TextView subject_name;

    private Runnable scrollRunnable;
    private boolean resumed = false;
    private Handler handler = new Handler();

    protected List<View> trendViews;
    private HomeFragmentPresenter presenter;
    private LiveListAdapter liveAdapter;
    private QAListAdapter qaAdapter;
    private BBSListAdapter bbsAdapter;
    protected CircleTrendViewPagerAdapter toadySubjectAdapter;
    private LiveGroup group;
    FloatMenuMgr menuMgr;

    public static HomeFragment newInstance() {
        return new HomeFragment();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home, null);
        unbinder = ButterKnife.bind(this, rootView);
        fixViewPagerSize();
        swipeRefresh.setOnRefreshListener(this);
        homeSign.setOnClickListener(this);
        homeMsg.setOnClickListener(this);
        homeTiaoli.setOnClickListener(this);
        homeRecord.setOnClickListener(this);
        homeZhenliao.setOnClickListener(this);
        homeSuggest.setOnClickListener(this);
        homeTask.setOnClickListener(this);
        bbsMore.setOnClickListener(this);
        qaMore.setOnClickListener(this);
        liveMore.setOnClickListener(this);
        SearchEdit.setOnClickListener(this);
        group_more.setOnClickListener(this);
        group_name.setOnClickListener(this);
        image.setOnClickListener(this);
        return rootView;
    }

    private void fixViewPagerSize() {
        //
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) homeBannerFrame.getLayoutParams();
        params.height = InitManager.getInstance().getScreenWidth() * 3 / 5;
        homeBannerFrame.setLayoutParams(params);
    }

    private void initFloatMenu(){
        menuMgr = new FloatMenuMgr();
        menuMgr.init(menuFrame, type -> {
            ((MainActivity) getActivity()).onFloatMenuClicked(type);
        });
    }

    public void closeFloatMenu(){
        menuMgr.closeMenu();
    }

    @Override
    public void initData() {
        SearchEdit.setHint(InitManager.getInstance().getOneSearchKeyword());
        initFloatMenu();
        initSmallViewPager();
        presenter = new HomeFragmentPresenter(this, getActivity());

        scrollRunnable = new Runnable() {
            @Override
            public void run() {
                if (mAdAdapter != null && mAdAdapter.getCount() > 0) {
                    int currentIndex = homeBannerViewpager.getCurrentItem();
                    int pos = currentIndex + 1;
                    if (pos > mAdAdapter.getCount() - 1) {
                        pos = 0;
                    }

                    homeBannerViewpager.setCurrentItem(pos);
                }
                if (resumed) {
                    handler.postDelayed(scrollRunnable, 3000);
                }
            }
        };
        presenter.getHomeData();
        initSmallViewPager();
    }

    private void initSmallViewPager(){
        smallPagerAdapter = new SmallPagerAdapter(getActivity());
        smallPager.setAdapter(smallPagerAdapter);

    }

    @Override
    public void onResume() {
        super.onResume();
        smallPager.startPlay(AppConfig.smallPagerDuration);
        resumed = true;
        handler.postDelayed(scrollRunnable, 3000);
        homeMsgUnread2.setText(InitManager.getInstance().unreadCount+"");
    }

    @Override
    public void onPause() {
        super.onPause();
        smallPager.stopPlay();
        resumed = false;
        handler.removeCallbacks(scrollRunnable);
        closeFloatMenu();


    }

    private void initBanners(final List<Ad> objs) {
        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (objs == null || objs.isEmpty()) {
                        homeBannerFrame.setVisibility(View.GONE);
                        return;
                    }
                    homeBannerFrame.setVisibility(View.VISIBLE);
                    if (mAdViews == null) {
                        mAdViews = new ArrayList<View>();
                    }
                    mAdViews.clear();
                    homeBannerRadiogroup.removeAllViews();
                    int size = objs.size();
                    int rightMargin = getActivity().getResources().getDimensionPixelSize(R.dimen.ad_radio_size);
                    for (int i = 0; i < size; i++) {
                        final Ad ad = objs.get(i);
                        final View adView = getActivity().getLayoutInflater().inflate(R.layout.layout_ad, null);
                        final ImageView img = (ImageView) adView.findViewById(R.id.ad_image);

                        ImageLoader.getInstance().loadImageView(getActivity(), ad.imgUrl, img);


                        mAdViews.add(adView);

                        adView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                WebViewActivity.start(getActivity(), ad.htmlUrl, ad.name,ad.imgUrl);
                            }
                        });

                        RadioButton radioButton = new RadioButton(getActivity());
                        radioButton.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
                        try {
                            radioButton.setBackgroundDrawable(getActivity().getResources().getDrawable(R.drawable.selector_ad_radiobutton));
                        } catch (Resources.NotFoundException e) {
                            e.printStackTrace();
                        }
                        RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(rightMargin, rightMargin);
                        if (i != (size - 1)) {
                            params.rightMargin = rightMargin;
                        }
                        homeBannerRadiogroup.addView(radioButton, params);


                    }
                    ((RadioButton) homeBannerRadiogroup.getChildAt(0)).setChecked(true);
                    mAdAdapter = new MyViewPagerAdapter(mAdViews);
                    homeBannerViewpager.setAdapter(mAdAdapter);
                    homeBannerViewpager.setOnPageChangeListener(HomeFragment.this);

                }
            });
        }
    }

    private void testCircle(List<BBSMoment> moments) {
        if (moments == null || moments.isEmpty()) {
            circleContainer.setVisibility(View.GONE);
            homeBbsBar.setVisibility(View.GONE);
            return;
        }
        circleContainer.setVisibility(View.VISIBLE);
        homeBbsBar.setVisibility(View.VISIBLE);

        circleContainer.removeAllViews();
        bbsAdapter = new BBSListAdapter(getActivity(), moments);
        for (int i = 0; i < moments.size(); i++) {
            View v = bbsAdapter.getView(i, null, null);
            if (i == moments.size() - 1) {
                v.findViewById(R.id.bbs_divider).setVisibility(View.GONE);
            }
            circleContainer.addView(v);
        }
    }

    private void testLive(List<LiveRoom> objs) {
        if (objs == null || objs.isEmpty()) {
            liveContainer.setVisibility(View.GONE);
            homeLiveBar.setVisibility(View.GONE);
            return;
        }
        liveContainer.setVisibility(View.VISIBLE);
        homeLiveBar.setVisibility(View.VISIBLE);

        liveContainer.removeAllViews();
        liveAdapter = new LiveListAdapter(getActivity(), objs);
        liveAdapter.setOnLiveRoomJoinListener(this);
        for (int i = 0; i < objs.size(); i++) {
            View v = liveAdapter.getView(i, null, null);
            if (i == 0) {
                v.findViewById(R.id.live_divider).setVisibility(View.GONE);

            }
            v.setTag(R.id.tag_home_live, objs.get(i));
            liveContainer.addView(v);
        }
    }

    private void testQa(List<QA> objs) {
        if (objs == null || objs.isEmpty()) {
            qaContainer.setVisibility(View.GONE);
            homeQaBar.setVisibility(View.GONE);
            return;
        }
        qaContainer.setVisibility(View.VISIBLE);
        homeQaBar.setVisibility(View.VISIBLE);

        qaContainer.removeAllViews();
        qaAdapter = new QAListAdapter(getActivity(), objs);
        qaAdapter.setOnQAPraiseClickListener(this);
        for (int i = 0; i < objs.size(); i++) {
            View v = qaAdapter.getView(i, null, null);
            if (i == 0) {
                v.findViewById(R.id.qa_divider).setVisibility(View.GONE);
            }
            v.setTag(R.id.tag_home_qa, objs.get(i));
            qaContainer.addView(v);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void refreshFragmentData() {
        Log.d(TAG, "refreshFragmentData");
        presenter.getHomeData();
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        ((RadioButton) homeBannerRadiogroup.getChildAt(position)).setChecked(true);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.home_sign:
            case R.id.home_msg:
            case R.id.home_record:
            case R.id.home_suggest:
            case R.id.home_zhenliao:
            case R.id.home_tiaoli:
            case R.id.home_task:
                if (InitManager.getInstance().getUser() == null) {
                    LoginActivity.startForResult(getActivity());
                    return;
                }
                if (StringUtil.isNullOrEmpty(InitManager.getInstance().getUser().mobile)) {
                    BindMobileActivity.startForResult(getActivity());
                    return;
                }

                if (id == R.id.home_sign) {
                    SignInActivity.start(getActivity());
                } else if (id == R.id.home_msg) {
                    homeMsgUnread.setVisibility(View.GONE);
                    MsgActivity.start(getActivity());
                } else if (id == R.id.home_record) {
                    CalendarActivity.start(getActivity());
                } else if (id == R.id.home_suggest) {
                    showProgress("请稍候...", false);
                    presenter.getAdvice();
                } else if (id == R.id.home_zhenliao) {
                    RecordEditActivity.start(getActivity(), RecordEditActivity.TYPE_ZHENLIAO);
                } else if (id == R.id.home_tiaoli) {
                    RecordEditActivity.start(getActivity(), RecordEditActivity.TYPE_TIAOLI);
                } else if (id == R.id.home_task) {
                    TaskActivity.start(getActivity());
                }
                break;
            case R.id.bbs_more:
                BBSListActivity.start(getActivity(), BBSListActivity.TYPE_ALL_CIRCLE);
                break;
            case R.id.live_more:
//                LiveListActivity.start(getActivity());
                ((MainActivity) getActivity()).switchToExpertTab(0);
                break;
            case R.id.qa_more:
//                QAListActivity.start(getActivity());
                ((MainActivity) getActivity()).switchToExpertTab(1);
                break;
            case R.id.search_edit:
                SearchActivity.start(getActivity(),SearchEdit.getHint().toString());
                break;
            case R.id.group_more:
                if (InitManager.getInstance().getUser() == null) {
                    LoginActivity.startForResult(getActivity());
                    return;
                }
                if (StringUtil.isNullOrEmpty(InitManager.getInstance().getUser().userToken)) {
                    BindMobileActivity.startForResult(getActivity());
                    return;
                }
                LiveGroupDetailActivity.start(getActivity());
                break;
            case R.id.group_detail_image:
            case R.id.group_name:
                LiveDetailActivity.start(getActivity(),group.firstRoomId,1);
                break;
            default:
                break;

        }
    }


    @Override
    public void onHomeDataGet(HomeData data) {
        Log.d(TAG, "onHomeDataGet: " + data.toString());
        if(data.unreadMsg2 > 0){
            homeMsgUnread2.setVisibility(View.VISIBLE);
            homeMsgUnread2.setText(data.unreadMsg2+"");
            InitManager.getInstance().unreadCount = data.unreadMsg2;
        } else {
            homeMsgUnread2.setVisibility(View.GONE);
        }
//        if (data.unreadMsg == 1) {
//            homeMsgUnread.setVisibility(View.GONE);
//        } else {
//            homeMsgUnread.setVisibility(View.GONE);
//        }
        initBanners(data.banners);
        testCircle(data.moments);
        testLive(data.lives);
        testQa(data.qas);
        initGroupData(data.group);
        initTodaySubject(data.todaySubjectName,data.todaySubject);
    }

    private void initTodaySubject(String name,List<TodaySubject> trends){
        if(trends == null || trends.isEmpty()){
            todaySubjectViewPager.setVisibility(View.GONE);
            home_subject_bar.setVisibility(View.GONE);
            return;
        }
        subject_name.setText("今日专题-"+name);
        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (trendViews == null) {
                        trendViews = new ArrayList<View>();
                    }
                    trendViews.clear();

                    int size = trends.size();

                    for (int i = 0; i < size; i++) {
                        final TodaySubject trend = trends.get(i);
                        final View trendView = getActivity().getLayoutInflater().inflate(R.layout.layout_item_home_todaysubject, null);
                        final ImageView avatar = (ImageView) trendView.findViewById(R.id.moment_avatar);
//                        final TextView nick = (TextView) trendView.findViewById(R.id.moment_nick);
//                        final TextView moment_time = (TextView) trendView.findViewById(R.id.moment_time);

                        final TextView content = (TextView) trendView.findViewById(R.id.moment_content);
                        ImageLoader.getInstance().loadImageView(getActivity(), trend.avatar, avatar);
                        content.setText(Html.fromHtml(StringUtil.getSimpleText(trend.content)));
//                        moment_time.setText(TimeUtil.getDisplayTimeMillis(trend.createTime));
//                        nick.setText(trend.nickname);
                        trendView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (InitManager.getInstance().getUser() == null) {
                                    LoginActivity.startForResult(getActivity());
                                    return;
                                }
                                if (StringUtil.isNullOrEmpty(InitManager.getInstance().getUser().userToken)) {
                                    BindMobileActivity.startForResult(getActivity());
                                    return;
                                }
                                LiveGroupDetailActivity.start(getActivity());
//                                if(trend.type.equals("1")){
//                                    BBSMomentDetailActivity.start(getActivity(),trend.id+"");
//                                } else if(trend.type.equals("2")){
//                                    QADetailActivity.start(getActivity(),trend.id);
//                                } else if(trend.type.equals("3")){
//                                    LiveDetailActivity.start(getActivity(),trend.id);
//                                }
                            }
                        });

                        trendViews.add(trendView);
                    }
                    toadySubjectAdapter = new CircleTrendViewPagerAdapter(trendViews);
                    todaySubjectViewPager.setAdapter(toadySubjectAdapter);
                    todaySubjectViewPager.startPlay(3000);
                }
            });
        }
    }

    private void initGroupData(LiveGroup group) {
        this.group = group;
        if(group==null){
            home_group_bar.setVisibility(View.GONE);
            home_group_bar2.setVisibility(View.GONE);
        } else {
            ImageLoader.getInstance().loadImageView(getActivity(), group.pic, image);
            group_name.setText(group.name);
            group_point.setText(group.consumePoint + "花生壳");
            group_room_num.setText(group.roomNum + "");
            group_enrole_count.setText(group.enroleNum+"");
        }
    }

    @Override
    public void onGetHomeDataFailed(String reason) {

    }

    @Override
    public void onAdviceGet(Advice advice) {
        dismissProgress();
        new BaseDialog().showAdviceDialog(getActivity(), advice);
    }

    @Override
    public void onGetAdviceFailed(String reason) {
        dismissProgress();
        showToast("获取建议失败");
    }

    @Override
    public void onJoinSuccess(LiveRoom room) {
        dismissProgress();
        for (int i = 0; i < liveContainer.getChildCount(); i++) {
            LiveRoom tag = (LiveRoom) liveContainer.getChildAt(i).getTag(R.id.tag_home_live);
            if (tag.roomId == room.roomId) {
                View v = liveContainer.getChildAt(i);
                TextView join = (TextView) v.findViewById(R.id.live_join);
                join.setText("进入直播间");
                v.setTag(room);
                break;

            }
        }
    }

    @Override
    public void onJoinFailed(String code, String reason) {
        dismissProgress();
        if (!ApiException.isApiException(code)) {
            showToast(reason);
        }
    }

    @Override
    public void onPraiseSuccess(QA qa) {
        dismissProgress();
        for (int i = 0; i < qaContainer.getChildCount(); i++) {
            QA tag = (QA) qaContainer.getChildAt(i).getTag(R.id.tag_home_qa);
            if (tag.id == qa.id) {
                View v = qaContainer.getChildAt(i);
                CheckBox prasiedCount = (CheckBox) v.findViewById(R.id.qa_prasied_count);
                prasiedCount.setChecked(qa.isPraised());
                prasiedCount.setText(qa.praiseCount + "");
                v.setTag(qa);
                break;

            }
        }
    }

    @Override
    public void onPraiseFailed(String reason) {
        dismissProgress();
        showToast(reason);
    }

    @Override
    public void onRefresh() {
        swipeRefresh.setRefreshing(false);
        refreshFragmentData();
    }

    @Override
    public void onLiveRoomJoin(LiveRoom room) {
        if (InitManager.getInstance().getUser() == null) {
            LoginActivity.startForResult(getActivity());
            return;
        }
        if (StringUtil.isNullOrEmpty(InitManager.getInstance().getUser().userToken)) {
            BindMobileActivity.startForResult(getActivity());
            return;
        }
        if (InitManager.getInstance().getUserId().equals(room.expertId)
                || InitManager.getInstance().getUserId().equals(room.serverId)) {
            LiveDetailActivity.start(getActivity(), room.roomId);
        } else {
            if (room.isEnroled == 0) {
                showProgress("正在报名...", false);
                presenter.joinRoom(room);
            } else {
                LiveRoomActivity.start(getActivity(), room);
            }
        }
    }

    @Override
    public void onQAPraiseClick(QA qa) {
        if (InitManager.getInstance().getUser() == null) {
            LoginActivity.startForResult(getActivity());
            return;
        }
        if (StringUtil.isNullOrEmpty(InitManager.getInstance().getUser().userToken)) {
            BindMobileActivity.startForResult(getActivity());
            return;
        }

        showProgress("请稍候...", false);
        presenter.praiseQA(qa);
    }
}
